package com.cwnu.onlinemall.controller;

import com.cwnu.onlinemall.pojo.MallCustomer;
import com.cwnu.onlinemall.pojo.ServerResult;
import com.cwnu.onlinemall.service.customerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
public class customerController {
    @Autowired
    customerService customerService;
    @RequestMapping("/customer/selectAll")
    public ServerResult selectAll(){
        return new ServerResult(0,"查询成功",customerService.selectAll());
    }

    @RequestMapping("/customer/selectById")
    public ServerResult selectById(Integer id){
        return new ServerResult(0,"查询成功",customerService.selectById(id));
    }

    @RequestMapping("/customer/deleteById")
    public ServerResult deleteById(Integer id){
        Integer row = customerService.deleteById(id);
        if(row >= 1){
            return new ServerResult(0,"删除成功",row);//返回数据是受影响的行数
        }
        else{
            return new ServerResult(1,"删除失败",null);
        }
    }

    @RequestMapping("/customer/insertById")
    public ServerResult insertById(MallCustomer mallCustomer){
        Integer row = customerService.insertById(mallCustomer);
        if(row >= 1){
            return new ServerResult(0,"插入成功",row);//返回数据是受影响的行数
        }
        else{
            return new ServerResult(1,"插入失败",null);
        }
    }

    @RequestMapping("/customer/updateById")
    public ServerResult updateById(MallCustomer mallCustomer){
        Integer row = customerService.updateById(mallCustomer);
        if(row >= 1){
            return new ServerResult(0,"修改成功",row);//返回数据是受影响的行数
        }
        else{
            return new ServerResult(1,"修改失败",null);
        }
    }

}
